<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : "{{ urlfor "ErpClassController.DataGrid"}}"
		,"bLengthChange": false
		,columns: [
			{"mDataProp" : "Id", "bSortable": false}
			,{"data" : "ClassName", "bSortable": false, render:function(data,type,full,meta){
				return 	(full.Level>0 ? '&nbsp;&nbsp;&nbsp;' : '') + full.Prefix+data;
			}}
			//,{"data" : "Pinyin", "bSortable": false}
			,{"data" : "CreatedAt", "bSortable": false, render:function(data, type, full, meta) {
				return timetrans(data);	
			}}
			,{"data" : "UpdatedAt", "bSortable": false, render:function(data, type, full, meta) {
				return timetrans(data);	
			}}
			 ,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"10%",
				"render": function ( data, type, full, meta ) { 
					btns = '<a class="am-btn am-btn-secondary am-btn-xs" href="javascript:;" onclick="return editErpClass('+ full.Id +')">编辑</a>';
					if(full.Status == '2') {
						btns += '&nbsp;<a href="javascript:;" class="am-btn am-btn-default am-btn-xs" onclick="delErpClass('+ full.Id +');return false;">启用</a>';
					} else {
						btns += '&nbsp;<a href="javascript:;" class="am-btn am-btn-danger am-btn-xs" onclick="delErpClass('+ full.Id +');return false;">停用</a>';
					}
					return btns;  
				}  
			 } 
		]
		,"serverSide": true
		,"bPaginate" : false
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : false //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
	
	function delErpClass(id) {
		layer.confirm('确定要操作所选记录吗？', function(index){
			$.post('{{ urlfor "ErpClassController.Delete"}}', {id:id}, function(res){
				if(res.code == 1) {
					layer.msg(res.msg)
				} else {
					tables.ajax.reload();
				}
				layer.close(index);
			}, 'json');
		});
	}
	
	function dialogReback() {
		tables.ajax.reload();
	}
	
	function editErpClass(Id) {
        var title = '添加类别';
        if (Id > 0) {
            title = "编辑类别"
        }
        var url = '{{ urlfor "ErpClassController.Edit"}}' + '/' + Id;
        layer.open({
            type: 2,
            title: title,
            shadeClose: false,
            shade: 0.2,
            maxmin: true,
            shift: 1,
            area: ['750px', '270px'],
            content: url
        });
		return false;
    }
	
</script>